class MailArticle < ActionMailer::Base
  def article_approved(user, article_id)
    setup_email(user)
    @subject    += 'Your article has been approved!'
    @body[:url]  =  BASE_URL + "content/showArticle?article_id=" + article_id

  end

  def article_disapproved(user, article_id)
    setup_email(user)
    @subject    += 'Your article has been disapproved!'
    @body[:url]  = BASE_URL + "content/showArticle?article_id=" + article_id
  end

  def article_submitted(user, article_id)
    setup_email(user)
    #a = ContentVersion.find_by_content_raw_id article_id
    # TODO Find the latest version of the article???
    @subject    += 'Your article has been submitted!'
    @body[:url]  =  BASE_URL + "content/showArticle?article_id=" + article_id

  end

  def article_comment(user, article_id)
    setup_email(user)
    @subject    += 'A comment was posted on your article!'
    @body[:url]  =  BASE_URL + "content/showArticle?article_id=" + article_id

  end

  def question_answer(user, question_id)
    setup_email(user)
    @subject    += 'An answer was posted for your question!'
    @body[:url]  =  BASE_URL + "content/showQuestion?question_id=" + question_id

  end

  protected
  def setup_email(user)
    u = User.find_by_id user
    @recipients  = "#{u.email}"
    @from        = "wae.web08@gmail.com"
    @subject     = "[Tourism Comm] "
    @sent_on     = Time.now
    @body[:user] = u.name
  end


end
